﻿<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">

    <script type='text/html' template>
        <input type='hidden' name='PID' value="{{ d.params.PID || '' }}" />
    </script>
    <div class='layui-form-item'>
        <label class='layui-form-label'>首页推荐类型</label>
        <div class='layui-input-block'>
            <div class='layui-input-inline'>
                <script type='text/html' template>
                    <select name='Type'>
                        <option value='0' {{ d.params.Type == '0' ? 'selected' : '' }}>热销商品</option>
                    </select>
                </script>
            </div>
        </div>
    </div>

    <div class='layui-form-item'>
        <label class='layui-form-label'>商品信息 <span style="color:red">*</span></label>
        <div class='layui-input-inline'>
            <script type='text/html' template>
                <input type='hidden' name='GoodIds' id="GoodIds" value='{{ d.params.GoodIds || '' }}'>
            </script>
        </div>
        <div class="layui-form-mid layui-word-aux">
            已选中<span style="color:red" id="num">0</span>个商品
            <button type="button" id="Guider" onclick="SelGoods()" class="layui-btn layui-btn-xs">选择商品</button>
            已推荐的商品不会重复保存
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>是否启用</label>
        <div class='layui-input-inline'>
            <script type='text/html' template>
                <select name="IsAble" id="IsAble">
                    <option value="1">启用</option>
                    <option value="0">不启用</option>
                </select>
            </script>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" value="确认" class="layui-btn">
        </div>
    </div>
</div>

<script type="text/javascript">

    var checkIDs = []; //选中的ID
    var lindex = "";
    var viewid = "";

    function SelGoods() {
        var view = layui.view;
        var admin = layui.admin;
        var $ = layui.$;
        admin.popup({
            title: '商品列表'
          , skin: 'layui-layer-lan'
          , area: ['85%', '96%']
          , zIndex: 1002
          , shadeClose: false
          , id: 'LAY-popup-content-add2'
          , success: function (layero, index) {
              lindex = index;
              view(this.id).render('/shop/shop_Goods/SelGoods').done(function () {
                  //form.render(null, 'layuiadmin-app-form-list');

                  var active = {
                      confirm: function () {
                          if (checkIDs.length === 0) {
                              return layer.msg('请选择数据');
                          }
                          debugger;
                          var count = checkIDs.length;
                          $("#num").text(count);
                          var goodids = JSON.stringify(checkIDs);
                          $("#GoodIds").val(goodids);

                          layer.close(lindex);
                      },
                      clearall: function () {
                          checkIDs = [];
                          $("#num").text(0);
                          $("#GoodIds").val("");

                          layer.close(lindex);
                      },
                  };


                  $('.layui-btn.layuiadmin-btn-list').on('click', function () {
                      var type = $(this).data('type');
                      active[type] ? active[type].call(this) : '';
                  });
              });
          }
        });
    }

    layui.use(['form'], function () {
        var form = layui.form;//required（必填项）phone（手机号）email（邮箱）url（网址）number（数字）date（日期）identity（身份证） 自定义值
    });
</script>
